//package com.easyapi.web.config;
//
//import com.easyapi.dao.entity.api.ApiCenterInterfaceInfo;
//import com.easyapi.server.service.execute.event.CacheLoadedEvent;
//import com.easyapi.web.controller.execute.GenerateInterfaceBaseController;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.event.EventListener;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
//import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//
//@Configuration
//public class DynamicApiConfig implements WebMvcConfigurer {
//
//    @Resource
//    private RequestMappingHandlerMapping handlerMapping;
//
//    @Resource
//    private ApplicationContext applicationContext;
//
//    @EventListener
//    public void registerDynamicApiRoutes(CacheLoadedEvent event) throws NoSuchMethodException {
//        Map<String, ApiCenterInterfaceInfo> pathMap = event.getPathMap();
//        GenerateInterfaceBaseController bean = applicationContext.getBean(GenerateInterfaceBaseController.class);
//        // 处理路径参数
//        List<String> pathList = new ArrayList<>(pathMap.keySet());// 假设路径中有 {id} 这样的参数
//        String[] paths = pathList.toArray(new String[0]);
//        // 动态注册路由到指定的处理方法
//            handlerMapping.registerMapping(
//                    RequestMappingInfo.paths(paths).methods(RequestMethod.POST).build(),
//                    bean,
//                    GenerateInterfaceBaseController.class.getDeclaredMethod(
//                            "generateInterfacePostExecute", Map.class, HttpServletRequest.class)
//            );
//    }
//}
